<?php

    class SupportJP
    {
        
    	public function checkfile_ok(&$object, $request, $str,$str_error_name)
    {
    	$flag_ok  = true;
    	
        if(isset($_FILES["$str"]) && @$_FILES["$str"]["name"] != "")
		{
			
			$file = $_FILES["$str"];
    		switch ($file['error']) 
    		{
    			case UPLOAD_ERR_OK:
    				
    				// success
    				break;
    			case UPLOAD_ERR_FORM_SIZE:
    				// only used if MAX_FILE_SIZE specified in form
    			case UPLOAD_ERR_INI_SIZE:
    				$object->addError($str_error_name, "_##The uploaded file was too large##_");
    				$flag_ok = false;
    				break;
    			case UPLOAD_ERR_PARTIAL:
    				$object->addError($str_error_name, "_##File was only partially uploaded##_");
    				$flag_ok = false;
    				break;
    			case UPLOAD_ERR_NO_FILE:
    				$object->addError($str_error_name, "_##No file was uploaded##_");
    				$flag_ok = false;
    				break;
    			case UPLOAD_ERR_NO_TMP_DIR:
    				$object->addError($str_error_name, "_##Temporary folder not found##_");
    				$flag_ok = false;
    				break;
    			case UPLOAD_ERR_CANT_WRITE:
    				$object->addError($str_error_name, "_##Unable to write file##_");
    				$flag_ok = false;
    				break;
    			case UPLOAD_ERR_EXTENSION:
    				$object->addError($str_error_name, "_##Invalid file extension##_");
    				$flag_ok = false;
    				break;
    			default:
    				$object->addError($str_error_name, "_##Unknown error code##_");
    				$flag_ok = false;
    		}
    		
    		if (!$flag_ok)  // neu false thi return  
    		{
    		return $flag_ok;	// false
    		}
    		
    		
    		
    		
    		$info = getimagesize($file['tmp_name']);
    		if(!$info)		
    		{
    			$object->addError($str_error_name, "_##Uploaded file was not an image##_");
    			return false;
    		}
    		
    		switch ($info[2])
    		{
    			case IMAGETYPE_PNG:
    			case IMAGETYPE_GIF:
    			case IMAGETYPE_JPEG:
    				break;
    			default:
    				$object->addError($str_error_name, "_##Invalid image type uploaded##_");	
    				return false;
    		}
    		
    		
		}
		
		else 
		{
			$object->addError($str_error_name, "_##Gif - JPg Please##_");
			return false;
		}
		
		
		return $flag_ok;
		
    	
    	
    }
    
    }
?>